package com.china.lottery.listener.dao;

import java.util.List;

import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.china.lottery.listener.dao.base.CommonDao;
import com.china.lottery.listener.dao.entity.TB_SP_JCZQ;

@Repository
public class TbSpJczqDao extends CommonDao{
	
	@Transactional
	public void save(TB_SP_JCZQ entity) {
		String sql="insert into TB_SP_JCZQS(cid,cgameid,citemid,cadddate,cvalue,cname,cindate,ctype,cvs) values(SEQ_TBSP_JCZQ_CID.NEXTVAL,?,?,?,?,?,?,?,?)";
		Query query=em.createNativeQuery(sql);
		query.setParameter(1, entity.getcGameId());
		query.setParameter(2, entity.getcItemId());
		query.setParameter(3, entity.getcAddDate());
		query.setParameter(4, entity.getcValue());
		query.setParameter(5, entity.getcName());
		query.setParameter(6, entity.getcIndate());
		query.setParameter(7, entity.getCtype());
		query.setParameter(8, entity.getCvs());

		query.executeUpdate();
		
		//em.persist(entity);
	}
	
	@SuppressWarnings("rawtypes")
	public List getTbSpJcZqByNameAndDateAndCgameId(String cname,String citemid,String cgameid){
		String sql="select * from TB_SP_JCZQS  where cname=? and citemid=? and cgameid=? order by cindate desc";
		Query query=em.createNativeQuery(sql);
		query.setParameter(1, cname);
		query.setParameter(2, citemid);
		query.setParameter(3, cgameid);
		
		@SuppressWarnings("unchecked")
		List<TB_SP_JCZQ> list= query.getResultList();
		
		return list;
	}


	
}
